<template>
    <div id="login">
        <div class="row mt-3">
            <div class="col-md-12 col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <img class="mx-auto d-block" src="../../src/assets/icon.png" />
                        <form @submit.prevent="onSubmit">
                            <div class="form-group">
                                <label for="username">登录名</label>
                                <input class="form-control" type="text" placeholder="输入用户名或邮箱" v-model="username">
                            </div>
                            <div class="form-group">
                                <label for="password">密码</label>
                                <input class="form-control" type="password" placeholder="输入密码" v-model="password">
                            </div>
                            <button class="btn btn-block btn-success" type="submit">登录</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data() {
            return {
                username: "",
                password: ""
            }
        },
        methods: {
            onSubmit() {
                Bmob.User.login(this.username, this.password).then(response => {
                    this.$store.dispatch("setUser", response);
                    this.$store.dispatch("setIsLogin");
                    this.$router.push({name: "Home"});
                }).catch(error => console.log(err));
            }
        },
        created() {
            this.$store.dispatch("logout");
        }
    }
</script>

<style scoped>

</style>